package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.SysRoleMenu;
import com.ruoyi.system.domain.dto.SysRoleDTO;
import com.ruoyi.system.domain.vo.SysRoleVO;
import com.ruoyi.system.mapper.SysRoleMenuMapper;
import com.ruoyi.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.service.ISysRoleService;

/**
 * 角色 业务层处理
 *
 * @author ruoyi
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper,SysRole> implements ISysRoleService {
    @Autowired
    private SysRoleMapper roleMapper;
    @Autowired
    private SysRoleMenuMapper roleMenuMapper;

    @Override
    public List<SysRoleVO> selectRoleList(Long projectId) {
        return roleMapper.selectRoleList(projectId);
    }

    @Override
    public void updateRoleMenu(SysRoleDTO.SysRoleMenuDTO params) {
        roleMenuMapper.deleteRoleMenuByRoleId(params.getRoleId());
        List<SysRoleMenu> roleMenuList = params.getMenuId().stream().map(item -> {
            SysRoleMenu roleMenu = new SysRoleMenu();
            roleMenu.setRoleId(params.getRoleId());
            roleMenu.setMenuId(item);
            return roleMenu;
        }).collect(Collectors.toList());
        roleMenuMapper.batchRoleMenu(roleMenuList);
    }

    @Override
    public List<Long> getRoleMenu(Long roleId) {
        return roleMenuMapper.getRoleMenu(roleId);
    }
}
